<?php
  PageUtil::addVar("stylesheet","
    <link href=\"".$stylepath."/post.css\" rel=\"stylesheet\">
    <link href=\"".$jspath."/photoswipe/photoswipe.css\" type=\"text/css\" rel=\"stylesheet\" />
    ");
  PageUtil::addVar("title",$post['title']);
  PageUtil::addVar("keywords",$metaKeyword);
  PageUtil::addVar("description",mb_substr(strip_tags($post['content']),0,120));
?>

<?php 
PageUtil::addVar("javascript_body","
<script src=\"".$jspath."/tinymce/tinymce.min.js\"></script>
<script>
  tinymce.init({
    selector: \"#elm1\",
    theme: \"modern\",
    font_size_style_values : \"xx-small,x-small,small,medium,large,x-large,xx-large\",
    height: 200,
    menubar : false,
    plugins: [
      \"advlist autolink  image lists charmap print preview hr anchor pagebreak spellchecker\",
      \"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking\",
      \"save table contextmenu directionality emoticons template paste textcolor importcss\"
    ],
    add_unload_trigger: false,
    toolbar: \"insertfile undo redo | bold italic | alignleft aligncenter alignright alignjustify | forecolor fullpage backcolor  preview  \",
    image_advtab: true,
    style_formats: [
      {title: 'Bold text', format: 'h1'},
      {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
      {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
      {title: 'Example 1', inline: 'span', classes: 'example1'},
      {title: 'Example 2', inline: 'span', classes: 'example2'},
      {title: 'Table styles'},
      {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]
    
  });
</script>
<!-- end tiny mce -->
<!-- style image galery box swipe  -->

<script type=\"text/javascript\" src=\"".$jspath."/photoswipe/lib/klass.min.js\"></script>
<script type=\"text/javascript\" src=\"".$jspath."/photoswipe/code.photoswipe.jquery-3.0.5.min.js\"></script>
<script type=\"text/javascript\">
  (function(window, $, PhotoSwipe){
    $(document).ready(function(){
      var options = {
        imageScaleMethod: \"fitNoUpscale\"
      };
      $(\".gallery a\").photoSwipe(options);
    });
  }(window, window.jQuery, window.Code.PhotoSwipe));
</script>
<!-- end -->

<script type=\"text/javascript\">
$(function (){
  $('.imggroup').mouseover(function() {
    var src = $(this).parent(\"a\").data(\"image\");
    var src2 =  $(this).parent(\"a\").attr(\"href\");
    var show = $(this).attr(\"class\");
    $('#large_image').html('<div class=\"gallery\"><a href=\"'+src2+'\"><img src=\"'+src+'\" alt=\"หมวดหมู่ : ภาพหน้าปก\" class=\"img-responsive\"/></a></div>');
    (function(window, $, PhotoSwipe){
      $(document).ready(function(){
        var options = {
          imageScaleMethod: \"fitNoUpscale\"
        };
        $(\".gallery a\").photoSwipe(options);
      });
    }(window, window.jQuery, window.Code.PhotoSwipe));
  });
});
</script>");
?>

<section class="content_block col-xs-12">
  <nav class="breadcrumb">
    <?php echo $breadcrumb;?>
  </nav>
  <section class="row">
    <section class="post_title col-xs-12">
      <a href="<?php echo base_url("post/view/".$post['url']);?>">
        <h1>
          <?php echo $post['title'];?>
        </h1>
      </a>
    </section>
  </section>

  <section class="row">
        <div class="col-xs-7">
        <?php
          if(!empty($first_images)){
        ?>
                <div id="large_image" class="col-xs-12">
                  <div class="gallery"><!-- use jqly image-->
                    <a href="<?php echo base_url($first_images['filepath']);?>"><img src="<?php echo base_url($first_images['medium']);?>" alt="<?php echo $post['title'];?>" class="img-responsive"/></a>
                  </div>
                </div>
          <?php
          }else{
            ?>
                <div id="large_image" class="col-xs-12">
                  <div class="gallery"><!-- use jqly image-->
                    <img src="<?php echo $imagepath."/not_available.jpg";?>" alt="<?php echo $post['title'];?>" class="img-responsive"/>
                  </div>
                </div>
            <?php
          }
        ?>
          <div id="group" class="col-xs-12">
            <div class="gallery" >
              <div class="row">
              <?php if(!empty($images)) {
                foreach($images as $image):
                  foreach ($image as $imageItem) {
                    ?>
                  <a href="<?php echo base_url($imageItem['filepath']);?>" data-image="<?php echo base_url($imageItem["medium"]); ?>" class="margin-bottom col-xs-3"><img src="<?php echo base_url($imageItem['small']);?>"  class="imggroup img-responsive" alt="<?php echo $post['title'];?> : สภาพภายนอก"/> </a>
                    <?php
                  }
                endforeach;
              }
              ?>
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-5">
          <div class="col-xs-12 post-view-price-detail">
            <div class="col-xs-12 post-view-price-type post-price-type-<?php echo $post["type"]["id"];?>">
              <?php echo $post["type"]["name"];?>
            </div>
            <div class="col-xs-12 post-view-price-number">
              <?php echo number_format(preg_replace("/[^0-9]/","", $post["meta"]["price"]), 0, '.', ','); ?> บาท
            </div> 
            <div class="col-xs-12 post-view-price-province">
              <?php echo (!empty($post["meta"]["province"]) ? Util::getProvince($post["meta"]["province"]) : "");?>
            </div> 
          </div>

          <h3 class="attribute">รายละเอียดสินค้า</h3>
          <dl class="dl-horizontal">
            <dt>ประเภทสินค้า</dt>
            <dd><?php echo (!empty($post["meta"]["condition"]) ? Util::getCondition($post["meta"]["condition"]):"ไม่ระบุ");?></dd>
            <dt>อายุการใช้งาน</dt>
            <dd><?php echo (!empty($post["meta"]["lifetime"]) ? $post["meta"]["lifetime"]:"-");?> <?php echo (!empty($post["meta"]["lifetime_unit"]) ? $post["meta"]["lifetime_unit"]:"-");?></dd>
            <dt>ของอยู่ที่</dt>
            <dd><?php echo (!empty($post["meta"]["province"]) ? Util::getProvince($post["meta"]["province"]) : "");?></dd>
          </dl>
          <?php
            if((!empty($post['is_dummy']) AND $post['is_dummy'] == 1)){
          ?>
          <h3 class="attribute">รายละเอียดผู้ขาย</h3>
          <dl class="dl-horizontal">
            <dt>ชื่อ</dt>
            <dd><?php echo (!empty($dummy["first_name"]) ? $dummy["first_name"]:"-");?> <?php echo (!empty($dummy["last_name"]) ? $dummy["last_name"]:"-");?></dd>
            <dt>เบอร์โทรศัพท์</dt>
            <dd><?php echo (!empty($dummy["phone"]) ? $dummy["phone"].", ":"");?><?php echo (!empty($dummy["mobile"]) ? $dummy["mobile"] : "");?></dd>
            <dt>อีเมล์</dt>
            <dd><?php echo (!empty($dummy["email"]) ? $dummy["email"]:"");?></dd>
            <dt>ที่อยู่</dt>
            <dd><?php echo (!empty($dummy["address"]) ? $dummy["address"]:"");?> <?php echo (!empty($dummy["district"]) ? $dummy["district"]:"");?> <?php echo (!empty($dummy["province"]) ? Util::getProvince($dummy["province"]) : "");?> <?php echo (!empty($dummy["zipcode"]) ? $dummy["zipcode"]:"");?></dd>
          </dl>
          <?php
            }else{
          ?>
          <h3 class="attribute">รายละเอียดผู้ขาย</h3>
          <dl class="dl-horizontal">
            <dt>ชื่อ</dt>
            <dd><?php echo (!empty($post["user"]["first_name"]) ? $post["user"]["first_name"]:"-");?> <?php echo (!empty($post["user"]["last_name"]) ? $post["user"]["last_name"]:"-");?></dd>
            <dt>เบอร์โทรศัพท์</dt>
            <dd><?php echo (!empty($post["user"]["phone"]) ? $post["user"]["phone"].", ":"");?><?php echo (!empty($post["user"]["mobile"]) ? $post["user"]["mobile"] : "");?></dd>
            <dt>อีเมล์</dt>
            <dd><?php echo (!empty($post["user"]["email"]) ? $post["user"]["email"]:"");?></dd>
            <dt>ที่อยู่</dt>
            <dd><?php echo (!empty($post["user"]["address"]) ? $post["user"]["address"]:"");?> <?php echo (!empty($post["user"]["district"]) ? $post["user"]["district"]:"");?> <?php echo (!empty($post["user"]["province"]) ? Util::getProvince($post["user"]["province"]) : "");?> <?php echo (!empty($post["user"]["zipcode"]) ? $post["user"]["zipcode"]:"");?></dd>
          </dl>
          <?php
            }
          ?>
        </div>
        
  </section>

  <section class="row">
    <section class="owner-post-option  col-xs-12">
      <div class="pull-left">
        <div class="fb-like" data-href="<?php echo base_url("post/view/".$post['url']);?>" data-layout="standard" data-action="like" data-show-faces="false" data-share="true"></div>
      </div>
      <?php
      if($this->ion_auth->logged_in()){
        ?>
          <div class="pull-right">
            <button type="button" class="btn btn-primary btn-xs btn-toolbar dropdown-toggle" data-toggle="dropdown">
              จัดการประกาศ
              <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
              <li><a href="<?php echo base_url('post/updatepost/'.$post['id']);?>" title="ดันประกาศขึ้นหน้าแรก">ดันประกาศขึ้นหน้าแรก</a></li>
              <li><a href="<?php echo base_url('post/add/'.$post['id']);?>" title="แก้ไขประกาศ">แก้ไขประกาศ</a></li>
              <li class="divider"></li>
              <li><a href="<?php echo base_url('post/complete/'.$post['id']);?>" title="แก้ไขประกาศ">ซื้อขายเรียบร้อย</a></li>
              <li class="divider"></li>
              <li><a href="<?php echo base_url('post/del/'.$post['id']);?>" title="ลบประกาศ">ลบประกาศ</a></li>
            </ul>
          </div>
        <?php
      }
      ?>
    </section>
  </section>
  <section class="row">
    <section class="col-xs-12">
      <h2>คำอธิบาย</h2>
      <article>
          <?php echo $post['content'];?>
      </article>
    </section>
  </section>

  <div class="row comment-box">
    <div class="col-xs-12">
      <h2>แสดงความคิดเห็น <span class="badge"><?php echo $comment_count;?></span></h2>
    </div>
    <?php
    if(!empty($comments)){
      foreach ($comments as $keyComment => $comment) {
      ?>
      <!-- Start Comment Block -->
      <div class="panel-body">
        <div class="row">
          <div class="col-xs-2 col-md-1">
            <img src="http://placehold.it/80" class="img-rounded img-responsive" alt="" /></div>
          <div class="col-xs-10 col-md-11">
            <div id="comment-id-<?php echo $comment["id"]; ?>" class="reply-detail-block">
              <a href="<?php echo base_url("post/view/".$post['url']);?>#comment-id-<?php echo $comment["id"]; ?>">
                <?php echo $comment["title"]; ?>
              </a>
              <small>
                <div class="mic-info">
                  โดย: <a href="<?php echo base_url("user/".$comment['username']);?>"><?php echo $comment["first_name"]." ".$comment["last_name"]; ?></a> (<?php echo Util::blindIP($comment["usr_ip"]); ?>) เมื่อ <?php echo $comment["cr_date"]; ?>
                </div>
              </small>
            </div>
            <div class="comment-text">
              <p>
                <?php echo $comment["content"]; ?>
              </p>
            </div>
            <?php
            if($this->ion_auth->in_group("admin")){
              ?>
              <div class="action">
                  <button type="button" class="btn btn-primary btn-xs" title="Edit">
                      <span class="glyphicon glyphicon-pencil"></span>
                  </button>
                  <button type="button" class="btn btn-success btn-xs" title="Approved">
                      <span class="glyphicon glyphicon-ok"></span>
                  </button>
                  <button type="button" class="btn btn-danger btn-xs" title="Delete">
                      <span class="glyphicon glyphicon-trash"></span>
                  </button>
              </div>
              <?php
            }

            ?>
            
          </div>
        </div>
      </div>
      <!-- End Comment Block -->
      <?php
      }//End comment foreach
    }else{
      ?>
      <div class="panel-body">
        <div class="panel panel-danger">
          <div class="panel-body text-center">
            <p>ยังไม่มีความเห็น</p>
          </div>
        </div>
      </div>
      <?php
    }
    ?>
  </div>
<?php
if($this->ion_auth->logged_in()){
?>
<div class="row">
    <div class="col-sm-12 col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <form accept-charset="UTF-8" action="<?php echo base_url('comment/reply'); ?>" method="POST">
                        <input name="pos_id" value="<?php echo $post["id"];?>" type="hidden">
                        <input name="type" value="post" type="hidden">
                        <textarea class="form-control counted" name="content" placeholder="Type in your message" rows="5" style="margin-bottom:10px;"></textarea>
                        <h6 class="pull-right" id="counter"></h6>
                        <button class="btn btn-info" type="submit">แสดงความเห็น</button>
                    </form>
                </div>
            </div>
        </div>
  </div>
<?php
}else{
?>
<div class="panel-body">
  <div class="panel panel-danger">
    <div class="panel-heading">
      <h3 class="panel-title">แจ้งเตือน!</h3>
    </div>
    <div class="panel-body text-center">
      <p>ต้องการแสดงความคิดเห็นกรุณาล็อคอิน แต่ถ้ายังไม่ได้สมัครสมาชิกคลิกสมัครสมาชิก</p>
      <a href="<?php echo base_url('user/login'); ?>" ><button type="button" class="btn btn-primary">ล็อคอิน</button></a>
      <a href="<?php echo base_url('user/register'); ?>" ><button type="button" class="btn btn-success" id="button_reg">สมัครสมาชิก</button></a>
    </div>
  </div>
</div>
<?php
}
?>
</section>
